<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .con{
        height: 20px;
        width: 500px;
        margin: 0 auto;
        background-color: skyblue;
    }
    .pg{
        height: 20px;
        background: thistle;
        width: 70px;
    }
</style>
<body>
    <div class="con" id="con">
        <div class="pg" id="pg" style="width: 0px;"></div>
    </div>
    <button id="start">开始</button>
    <button id="pause">暂停</button>
</body>
<script>
    var con = document.getElementById("con");
    var pg = document.getElementById("pg");
    var start = document.getElementById("start");
    var final = document.getElementById("final");
    var pause = document.getElementById("pause");
    var intervalID;
    start.onclick = function(){
        intervalID = setInterval(function(){
            var width = pg.style.width;
            width = parseInt(width) +1;
            pg.style.width = width + "px";
            if(width == 500){
                clearInterval(intervalID);
            }
        },100)//时间间隔

        pause.onclick = function(){
            clearInterval(intervalID);
        }
    }
</script>
</html>